package com.anyun.collect.extensions

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.anyun.collect.R

/**collect
 * Created by lzw on 2019/12/4. 17:44:31
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */

fun FragmentManager.detach(){
    findFragmentById(R.id.container)?.also {
        beginTransaction().detach(it).commit()
    }
}

fun FragmentManager.attach(fragment: Fragment, tag: String){
    if (fragment.isDetached){
        beginTransaction().attach(fragment).commit()
    }else{
        beginTransaction().add(R.id.container,fragment,tag).commit()


    }
    beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit()
}